﻿@model S4Store.Models.AfterSaleReport.AfterSaleSellerDecoratingReportModel
@{
    Layout = null;

    //公式部分
    List<dynamic> listMonth = new List<dynamic>();
    List<dynamic> listDay = new List<dynamic>();
    string name = "";
    for (var dt = Model.BarModel.Start ?? DateTime.Now.AddMonths(-6); dt <= Model.BarModel.End; dt = dt.AddMonths(1))
    {
        var query = Model.MonthConfig.Where(o => o.AddTime.Year == dt.Year && o.AddTime.Month == dt.Month).FirstOrDefault();
        if(query!=null)
        {
            if (string.IsNullOrEmpty(name)) 
            {
                name = query.Employee.Name;
            }
            listMonth.Add(new
            {
                时间 = dt,
                目标用品销售额 = query.JPMBXSE_CompetitiveSaleTarget
            });
        }else{
            listMonth.Add(new
            {
                时间 = dt,
                目标用品销售额 = 0
            });
        }

        var queryDay = Model.DayData.Where(o => o.AddTime.Year == dt.Year && o.AddTime.Month == dt.Month);
        if(queryDay.Count()>0)
        {

            
            listDay.Add(new
            {
                时间 = dt,
                
                //M9/J9
                累计用品销售额 = queryDay.Sum(o=>o.LJJPXSE)
            });
        }else
        {
            listDay.Add(new
            {
                时间 = dt,
                累计用品销售额 = 0
            });
        }
    }
    
    //图标部分
    S4Store.Models.Chart.Line ChartModel = new S4Store.Models.Chart.Line();
    ChartModel.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel.IsRate = false;
    ChartModel.YAxis = "用品销售历史数据";

    foreach (var item in listMonth.GroupBy(o => o.时间))
    {
        ChartModel.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series = new S4Store.Models.Chart.ChartSeries();
    series.Name = "目标用品销售额";
    foreach (var item in listMonth)
    {
        series.Data.Add(item.目标用品销售额);
    }
    ChartModel.Serieses.Add(series);
    S4Store.Models.Chart.ChartSeries series1 = new S4Store.Models.Chart.ChartSeries();
    series1.Name = "累计用品销售额";
    foreach (var item in listDay)
    {
        series1.Data.Add(item.累计用品销售额);
    }
    ChartModel.Serieses.Add(series1);



<div style="height:100%; overflow:auto">

@Html.Action("ReportBar", "Common", Model.BarModel)
<div class="pagetitle">@(name)用品销售历史查询</div>
@Html.Partial("../Chart/Line", ChartModel)
</div>
}